﻿Public Class EditCourse
    Public Response As MessageBoxResult = MessageBoxResult.Cancel
    Private subj As Course

    Public Sub New(ByRef value As Course)
        InitializeComponent()

        subj = value
        populateProfessorList()
        fillForm()
    End Sub

    Public Sub populateProfessorList()
        For Each prof As Professor In Course.professorList
            courseProfessor.Items.Add(prof.name)
        Next
    End Sub

    Public Sub fillForm()
        courseName.Text = subj.name

        If subj.parent Is Nothing Then
            courseProfessor.SelectedIndex = 0
        Else
            courseProfessor.SelectedIndex = Course.professorList.FindIndex(AddressOf SameProfessor)
        End If

    End Sub

    Public Sub OK_Click()
        saveForm()
        Response = MessageBoxResult.OK
        Me.Hide()
    End Sub

    Public Sub Cancel_Click()
        Response = MessageBoxResult.Cancel
        Me.Hide()
    End Sub

    Public Sub saveForm()
        subj.name = courseName.Text
        'subj.color = courseColor.Text
        subj.parent = Course.professorList(courseProfessor.SelectedIndex)
        subj.notes = courseNotes.Text
    End Sub

    Private Function SameProfessor(ByVal value As Professor) As Boolean

        If value.guid = subj.parent.guid Then
            Return True
        Else
            Return False
        End If
    End Function
End Class
